package comp
{
	use namespace comp_layout;
	
	import comp.style.css.CssAchieve;
	
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;

	/**
	 * 块控件
	 * 
	 */
	public class Block extends UIComponent
	{
		include "style/SkinStyle" //皮肤属性
		include "style/BorderStyles";//包含样式
		include "style/PaddingStyles";//包含样式

		public function Block()
		{
			super();
			this._themeName="comp::Block";
		}
		
		//***************** override ***************
		override public  function set height(value:Number):void
		{
			super.height = value;
			if(this.initialized)
				merge();
		}
		
		override public  function set width(value:Number):void
		{
			super.width = value;
			if(this.initialized)
				merge();
		}
		
		override protected function addedChild(child:DisplayObject):void
		{
			super.addedChild(child);
			if(child!=this.currentSkin)
			{
				child.x=child.x+this.getStyle("paddingLeft");
				child.y=child.y+this.getStyle("paddingTop");
			}
		}
		
		override protected function merge():void
		{
			CssAchieve.mergeTemplate(this);
			CssAchieve.mergeBackGrounde(this);
			
			this.wholeRect=new Rectangle(0,0,this.width,this.height);
		}
		
		override public function styleChanged(styleProp:String,newValue:*):void
		{
			super.styleChanged(styleProp,newValue);
			if(styleProp=="template")
			{
				this.template=newValue;
				this.merge();
			}else if(this.initialized && styleProp=="borderColor")
			{
				this.borderColor=newValue;
				this.merge();
			}

		}
	}
}